package com.stage.battle
{	
	import com.resource.ResAsset;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	
	import flashx.textLayout.debug.assert;
	
	/**
	 * 带有cd的技能icon
	 * 添加enterFrame调用
	 */
	public class SkillIcon extends Sprite
	{
		private var _icon:Bitmap = new Bitmap;
		private var _coldDown:MovieClip;
		private var _cdTime:Number = 0;
		private var _startTime:Number;
		private var _isCD:Boolean = false;
		
		public function SkillIcon()
		{
			super();
			addChild(_icon);
		}
		
		public function set icon(value:BitmapData):void{
			_icon.bitmapData = value;
		}
		
		public function enterFrame():void{
			if(!_isCD){
				var now:Number = (new Date).time;
				if(_coldDown){
					_coldDown.gotoAndStop(int((now - _startTime) / _cdTime * _coldDown.totalFrames));
				}
				if(now - _startTime >= _cdTime){
					_isCD = true;
				}
			}
		}
		
		public function startCD():void{
			_isCD = false;
			_startTime = (new Date).time;
		}
		
		public function set cdTime(value:Number):void{
			_cdTime = value;
			if(_cdTime > 0 && !_coldDown){
				_coldDown = new (ResAsset.coldDown);
				addChild(_coldDown);
			}
		}
		
		public function get isCD():Boolean{
			return _isCD;
		}
	}
}